package org.pupil.rpc.filter;

import java.util.ArrayList;
import java.util.List;

/**
 * 拦截器链
 */
public class FilterChain {

    private List<Filter> filters = new ArrayList<>();

    /**
     * 添加单个拦截器
     * @param filter
     */
    public void addFilter(Filter filter){
        filters.add(filter);
    }

    /**
     * 添加多个拦截器
     * @param filters
     */
    public void addFilter(List<Object> filters){
        for (Object filter : filters) {
            addFilter((Filter) filter);
        }
    }

    /**
     * 责任链连模式 调用doFilter 处理 filterData
     * @param data
     */
    public void doFilter(FilterData data){
        for (Filter filter : filters) {
            filter.doFilter(data);
        }
    }
}
